package com.ruoyi.contract.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;

import com.ruoyi.contract.domain.ConOperLog;
import com.ruoyi.contract.service.IConOperLogService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by zhangxiang on 2021/10/20.
 */
@RestController
@RequestMapping("/conLog")
public class ConOperLogController {

    @Autowired
    IConOperLogService conOperLogService;

    @Autowired
    ISysUserService iSysUserService;


    @GetMapping("/list/{conId}")
    public AjaxResult list(@PathVariable("conId")Long conId){
        List<ConOperLog> conOperLogList = conOperLogService.list(new QueryWrapper<ConOperLog>().lambda().eq(ConOperLog::getConId,conId).orderByAsc(ConOperLog::getOperTime));
        for(int i=0;i<conOperLogList.size();i++){
            ConOperLog conOperLog = conOperLogList.get(i);
            if(conOperLog.getOperName()!=null){
                SysUser sysUser = iSysUserService.selectUserByUserName(conOperLogList.get(i).getOperName());
                conOperLog.setNickName(sysUser.getNickName());
            }
        }

        return AjaxResult.success(conOperLogList);
    }

}
